﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<OpenAPI.Model.OAuth.ConsumerInfo>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Consumer Manage - Open API Control Panel
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <fieldset>
        <legend>Consumer Manage &gt; Modify Consumer</legend>
        <table border="0" cellspacing="0" width="100%">
            <tr>
                <td width="150">
                    Consumer Key<font color="red">*</font>
                </td>
                <td>
                    <% =Html.TextBox("txtOAUTH_CONSUMER_KEY", Model.OAUTH_CONSUMER_KEY, new { @style = "width:250px",@disabled="disabled" })%>
                </td>
            </tr>
            <tr>
                <td width="150">
                    Consumer Secret<font color="red">*</font>
                </td>
                <td>
                    <% =Html.TextBox("txtOAUTH_CONSUMER_SECRET", Model.OAUTH_CONSUMER_SECRET, new { @style = "width:250px", @disabled = "disabled" })%>
                </td>
            </tr>
            <tr>
                <td width="150">
                    Consumer Name<font color="red">*</font>
                </td>
                <td>
                    <% =Html.TextBox("txtCONSUMER_NAME", Model.CONSUMER_NAME, new { @style = "width:250px" })%>
                </td>
            </tr>
            <tr>
                <td width="150">
                    Request URL<font color="red">*</font>
                </td>
                <td>
                    <% =Html.TextBox("txtCONSUMER_REQUEST_URL", Model.CONSUMER_REQUEST_URL, new { @style = "width:250px" })%>
                </td>
            </tr>
            <tr>
                <td width="150">
                    Callback URL<font color="red">*</font>
                </td>
                <td>
                    <% =Html.TextBox("txtCONSUMER_CALLBACK", Model.CONSUMER_CALLBACK_URL, new { @style = "width:250px" })%>
                </td>
            </tr>
            <tr>
                <td width="150">
                    Consumer Level<font color="red">*</font>
                </td>
                <td>
                    <% =Html.DropDownList("ddlCONSUMER_LEVEL", ViewData["Levels"] as SelectList, new { @style = "width:250px"})%>
                </td>
            </tr>
            <tr>
                <td width="150">
                    Consumer Email
                </td>
                <td>
                    <% =Html.TextBox("txtCONSUMER_EMAIL", Model.CONSUMER_EMAIL, new { @style = "width:250px" })%>
                </td>
            </tr>
            <tr>
                <td width="150">
                    &nbsp;
                </td>
                <td>
                    <input type="button" id="btnConsumerModify" name="btnConsumerModify" value="Modify consumer" />
                    <input type="button" id="btnBackToList" name="btnBackToList" value="Back To List"
                        onclick="javascript:location.href='/Consumer/ConsumerList';" />
                </td>
            </tr>
        </table>
    </fieldset>

    <script type="text/javascript" language="javascript">

        //json: Modify Consumer
        $().ready(function() {
            $("#btnConsumerModify").click(function() {

                var oauth_consumer_key = $("input[name='txtOAUTH_CONSUMER_KEY']")[0].value;
                var oauth_consumer_secret = $("input[name='txtOAUTH_CONSUMER_SECRET']")[0].value;

                var consumer_name = $("input[name='txtCONSUMER_NAME']")[0].value;
                var consumer_request = $("input[name='txtCONSUMER_REQUEST_URL']")[0].value;
                var consumer_callback = $("input[name='txtCONSUMER_CALLBACK']")[0].value;
                var consumer_level = $("#ddlCONSUMER_LEVEL").val();
                var consumer_email = $("input[name='txtCONSUMER_EMAIL']")[0].value;


                $("input[name='btnConsumerModify']")[0].disabled = "disabled";
                $("input[name='btnConsumerModify']")[0].value = "Modify consumer...";

                $.post("/Consumer/ConsumerModify?" + new Date(), {
                    Action: "post",
                    oauth_consumer_key: oauth_consumer_key,
                    oauth_consumer_secret: oauth_consumer_secret,

                    consumer_name: consumer_name,
                    consumer_request: consumer_request,
                    consumer_callback: consumer_callback,
                    consumer_level: consumer_level,
                    consumer_email: consumer_email
                }, function(result) {
                    if (result.FLAG) {
                        alert(result.DESC);
                        $("input[name='btnConsumerModify']")[0].disabled = "";
                        $("input[name='btnConsumerModify']")[0].value = "Modify consumer";
                    }
                    else {
                        alert(result.DESC);
                        $("input[name='btnConsumerModify']")[0].disabled = "";
                        $("input[name='btnConsumerModify']")[0].value = "Modify consumer";
                    }
                })
            })
        })
    </script>

</asp:Content>
